import {
  getList,
  addList,
  updateList,
  deleteList
} from '@/api/classify.js';

import {getQuestionsApi,postQuestionsApi,updateQuestionsApi,delQuestionsApi} from '../../api/examManger'

export default {
  namespaced: true,
  state: {
      list: [],
      examlist:[],
      pageSize:5,
      currentPage:1,
      order:'desc',
      by:'id',
      total:0
  },
  mutations: {
      setList(state, data) {
          state.list = data
      },
      SET_EXAM(state,examlist){
        state.examlist=examlist
      },
      SET_CURRENT(state,currentPage){
        state.currentPage=currentPage
      },
      SET_PAGESIZE(state,pageSize){
        state.pageSize=pageSize
      },
      SET_TOTAL(state,total){
        state.total=total
      }
  },
  actions: {
      async getListFun({
          commit
      }) {
          let res = await getList();
          commit("setList", res.data)
          // console.log(res.data)
      },
      async addListFun({
          commit
      }, data) {
          await addList(data);
      },
      async updateListFun({
          commit
      }, data) {
          await updateList(data);
          // console.log(data)
      },
      async deleteListFun({
          commit
      }, id) {
          await deleteList(id);
      },
      async getExam({commit,state},searchValue){
        let r=await getQuestionsApi({
          pageSize:state.pageSize,
          currentPage:state.currentPage-1,
          order:state.order,
          by:state.by,
          searchValue:searchValue.ipt
        })
        commit('SET_EXAM',r.data)
        commit('SET_TOTAL',r.total)
        // console.log(r.total)
        // console.log(r.data)
      },
      async postExam({commit},form){
        await postQuestionsApi(form)
      },
      async updateQuestions({commit},form){
        await updateQuestionsApi(form)
        // console.log(form)
      },
      async delQuestions({commit},id){
        await delQuestionsApi(id)
      }
  },
}